var idcardProvince={};

var setIdcardProvince=function(obj){
    idcardProvince=obj;
}


var cardPrefixLengthType = [10, 9, 8, 7, 6, 5, 4, 3, 2];
var bulidIdcard=function(idcardMap){
    var idcard = idcardMap["idcard"];
    if (idcard) {
        if (15 == idcard.length()) {
            idcard = contertToNewCardNumber(idcard);
        }
        var pr = idcard.substring(0, 2);
        var provinceCode = idcardProvince[pr];
        if (provinceCode != null) {
            idcardMap["idcard_province"]= provinceCode.province_name;
            var cityCode = provinceCode.cityMap[idcard.substring(2, 4)];
            if (cityCode != null) {
                idcardMap["idcard_city"]=cityCode.city_name;
            }
        }

        var idcard_birth=new Date(idcard.substring(6, 10),idcard.substring(10, 12),idcard.substring(12, 14));
        idcardMap["idcard_birth"]= idcard_birth;

        var num = parseInt(idcard.substring(16, 17));
        idcardMap["idcard_sex"]= num % 2;
    }
}

function contertToNewCardNumber(oldCardNumber) {
    var car="";
    car+=oldCardNumber.substring(0, 6);
    car+="19";
    car+=oldCardNumber.substring(6);
    car+=calculateVerifyCode(oldCardNumber);
    return car;
}

var VERIFY_CODE = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
/**
 * 18位身份证中，各个数字的生成校验码时的权值
 */
var VERIFY_CODE_WEIGHT = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];

function calculateVerifyCode(cardNumber) {
    var sum = 0;
    for (var i = 0; i < 18 - 1; i++) {
        sum +=  parseInt(cardNumber.charAt(i))* VERIFY_CODE_WEIGHT[i];
    }
    return VERIFY_CODE[sum % 11];
}
